home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7861 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  63.7 KB

  1. Path: news.synopsys.com!jbuck
  2. From: jbuck@synopsys.com (Joe Buck)
  3. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  4. Subject: FAQ for g++ and libg++, plain text version [Revised 15 Feb 1996]
  5. Supersedes: <g++FAQ_02_01_1996_texi@synopsys.com>
  6. Followup-To: poster
  7. Date: 15 Feb 1996 22:51:03 GMT
  8. Organization: Synopsys, Inc.
  9. Approved: news-answers-request@MIT.edu
  10. Expires: 15 Mar 1996 00:00:00 GMT
  11. Message-ID: <g++FAQ_02_15_1996_texi@synopsys.com>
  12. NNTP-Posting-Host: deerslayer.synopsys.com
  13. Originator: jbuck@deerslayer
  14.  
  15. Archive-name: g++-FAQ/plain
  16. Last-modified: 15 Feb 1996
  17. Frequency: bimonthly
  18.  
  19. [ this is the plain text version, the parent is the texinfo version ]
  20.  
  21.  
  22. FAQ for g++ and libg++, by Joe Buck (jbuck@synopsys.com)
  23. ********************************************************
  24.  
  25.    This is a list of frequently asked questions (FAQ) for g++ users;
  26. thanks to all those who sent suggestions for improvements.  Thanks to
  27. Marcus Speh for doing the index.  A hypertext version is available on
  28. the World Wide Web at `http://www.cygnus.com/misc/g++FAQ_toc.html'.
  29.  
  30.    Please send updates and corrections to the FAQ to
  31. `jbuck@synopsys.com'.  Please do *not* use me as a resource to get your
  32. questions answered; that's what gnu.g++.help is for and I don't have
  33. the time to support the net's use of g++.
  34.  
  35.    Many FAQs, including this one, are available on the archive site
  36. "rtfm.mit.edu"; see
  37. `ftp://rftm.mit.edu/pub/usenet/news.answers'.  This FAQ may be found in
  38. the subdirectory g++-FAQ.
  39.  
  40.    This FAQ is intended to supplement, not replace, Marshall Cline's
  41. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  42. Especially if g++ is the first C++ compiler you've ever used, the
  43. question "How do I do <X> with g++?" is probably really "How do I do
  44. <X> in C++?".  You can find this FAQ at
  45. `ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++', or in HTML form at
  46. `http://cosmos2.phy.tufts.edu/~swinitzk/cppfaq/cppfa.htm'.
  47.  
  48. The latest poop - gcc-2.7.x
  49. ***************************
  50.  
  51.    This section is intended to describe more recent changes to g++,
  52. libg++, and such.  Some things in this section will eventually move
  53. elsewhere.
  54.  
  55.    As I write this, gcc-2.7.1 has just been released, followed in quick
  56. succession by gcc-2.7.2.  *Do not use version 2.7.1*, as there are a
  57. few serious problems.  I haven't had time to fully evaluate it yet, so
  58. some material below that refers to 2.7.0 may now be obsolete.
  59.  
  60.    I haven't had a lot of time to whip out this section yet, so
  61. suggestions for improvement are welcome.
  62.  
  63. g++ seems to want a const constructor.  What's that?
  64. ====================================================
  65.  
  66.    gcc-2.7.1 introduced a bug that causes the compiler to ask for a
  67. const constructor (there's no such thing in C++) in certain situations
  68. where a const object appears in a template class.  Most cases have been
  69. fixed in gcc-2.7.2, but unfortunately not all.  Still, if you're running
  70. gcc-2.7.1 and have this problem, upgrade to 2.7.2; it is a vast
  71. improvement.
  72.  
  73.    The default constructor for the template `pair' in ObjectSpace's
  74. implementation of STL triggers the bug in one place, for gcc 2.7.2.  If
  75. you're using ObjectSpace<STL> and having this problem, simply change
  76. the default constructor from
  77.  
  78.      os_pair () : first (T1 ()), second (T2 ()) {}
  79.  
  80.    to just
  81.  
  82.      os_pair () {}
  83.  
  84.    Once this is done, ObjectSpace<STL> works fairly well.
  85.  
  86. gcc-2.7.0 breaks declarations in "for" statements!
  87. ==================================================
  88.  
  89.    gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables
  90. declared in for loops.
  91.  
  92.      for (int i = 1; i <= 10; i++) {
  93.              // do something here
  94.      }
  95.      foo(i);
  96.  
  97.    In the above example, most existing C++ compilers would pass the
  98. value 11 to the function `foo'.  In gcc 2.7 and in the ANSI/ISO working
  99. paper, the scope of `i' is only the for loop body, so this is an error.
  100. So that old code can be compiled, the new gcc has a flag
  101. `-fno-for-scope' that causes the old rule to be used.
  102.  
  103.    As of 2.7.1, the compiler attempts to issue warnings about code that
  104. has different meanings under the two sets of rules, but the code is not
  105. perfect: the intent was that code that has valid, but different,
  106. meanings under the ARM rules and the working paper rules would give
  107. warnings but have the new behavior, and this doesn't seem to happen.
  108.  
  109.    The `-ffor-scope' flag under 2.7.1 and 2.7.2 gives the 2.7.0
  110. behavior.
  111.  
  112. What's new in version 2.7.0 of gcc/g++
  113. ======================================
  114.  
  115.    The long-awaited version 2.7.0 of gcc/g++ (along with a matching
  116. version of libg++) have now been released (now, so have 2.7.1 and
  117. 2.7.2).  This represents a great deal of work on the part of the g++
  118. maintainers to fix outstanding bugs and move the compiler closer to the
  119. current ANSI/ISO standards committee's working paper, including
  120. supporting many of the new features that have been added to the
  121. language.  I recommend that everyone read the NEWS file contained in
  122. the distribution (and that system administrators make the file
  123. available to their users).  I've borrowed liberally from this file here.
  124.  
  125.    If any features seem unfamiliar, you will probably want to look at
  126. the recently-released public review copy of the C++ Working Paper:
  127.    * PostScript and PDF (Adobe Acrobat): see
  128.      `ftp://research.att.com/dist/c++std/WP'.
  129.  
  130.    * HTML and ASCII versions: see `ftp://ftp.cygnus.com/pub/g++'.
  131.  
  132.    * World Wide Web: see `http://www.cygnus.com/misc/wp/'.
  133.  
  134.    Here are the main points:
  135.  
  136.    * As described above, the scope of variables declared in the
  137.      initialization part of a for statement has been changed; such
  138.      variables are now visible only in the loop body.  Use
  139.      `-fno-for-scope' to get the old behavior.  You'll need this flag
  140.      to build groff version 1.09, Ptolemy, and many others.
  141.  
  142.    * Code that does not use #pragma interface/implementation will most
  143.      likely shrink dramatically, as g++ now only emits the vtable for a
  144.      class in the translation unit where its first non-inline,
  145.      non-abstract virtual function is defined.
  146.  
  147.    * Support for automatic template instantiation has *not* been enabled
  148.      in the official distribution, due to a disagreement over design
  149.      philosophies.  But you can get a patch from Cygnus to turn it on;
  150.      retrieve the patch from
  151.      `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz' to patch
  152.      gcc-2.7.2 (there are also patches for earlier gcc versions).
  153.  
  154.    * Support for exception handling has been improved; more targets are
  155.      now supported, and throws will use the RTTI mechanism to match
  156.      against the catch parameter type.  You must give the
  157.      `-fhandle-exceptions' to turn it on.  You must give the `-frtti'
  158.      switch to enable catching of derived exception objects with
  159.      handlers for the base exception class; if `-frtti' is not given,
  160.      only exact type matching works.
  161.  
  162.      Optimization is *not supported* with `-fhandle-exceptions'; no
  163.      need to report this as a bug.  You'll probably get an internal
  164.      compiler error if you try it.  (Q: is this better in 2.7.1?).
  165.  
  166.      For exception handling to work with 2.7.0 your CPU must be a SPARC,
  167.      RS6000/PowerPC, 386/486/Pentium, or ARM.  Release 2.7.1 added
  168.      support for the Alpha, and "m68k is rumored to work on some
  169.      platforms" and "VAX may also work" (according to Mike Stump).  It
  170.      still doesn't work on HP-PA or MIPS platforms.
  171.  
  172.    * Support for Run-Time Type Identification has been added with
  173.      `-frtti'.  This support is still in alpha; one major restriction
  174.      is that any file compiled with `-frtti' must include `<typeinfo>'
  175.      (*not* `typeinfo.h' as the NEWS file says).  Also, all code you
  176.      link with (including libg++) has to be built with `-frtti', so
  177.      it's still tricky to use.
  178.  
  179.    * Synthesis of compiler-generated constructors, destructors and
  180.      assignment operators is now deferred until the functions are used.
  181.  
  182.    * The parsing of expressions such as `a ? b : c = 1' has changed from
  183.      `(a ? b : c) = 1' to `a ? b : (c = 1)'.  This is a new C/C++
  184.      incompatibility brought to you by the ANSI/ISO standards committee.
  185.  
  186.    * The operator keywords and, and_eq, bitand, bitor, compl, not,
  187.      not_eq, or, or_eq, xor and xor_eq are now supported.  Use `-ansi'
  188.      or `-foperator-names' to enable them.
  189.  
  190.    * The `explicit' keyword is now supported.  `explicit' is used to
  191.      mark constructors and type conversion operators that should not be
  192.      used implicitly.
  193.  
  194.    * Handling of user-defined type conversion has been improved.
  195.  
  196.    * Explicit instantiation of template methods is now supported.  Also,
  197.      `inline template class foo<int>;' can be used to emit only the
  198.      vtable for a template class.
  199.  
  200.    * With -fcheck-new, g++ will check the return value of all calls to
  201.      operator new, and not attempt to modify a returned null pointer.
  202.  
  203.    * collect2 now demangles linker output, and c++filt has become part
  204.      of the gcc distribution.
  205.  
  206.    * Improvements to template instantiation: only members actually used
  207.      are instantiated.
  208.  
  209. How do I use the new repository code?
  210. =====================================
  211.  
  212.    Because there is some disagreement about the details of the template
  213. repository mechanism, you'll need to obtain a patch from Cygnus Support
  214. to enable the 2.7.2 repository code.  You can obtain the patch by
  215. anonymous FTP: `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz'.
  216.  
  217.    There are patches for 2.7.0 and 2.7.1 in the same directory, though
  218. if you're going to rebuild the compiler you should use the latest one.
  219.  
  220.    After you've applied the patch, the `-frepo' flag will enable the
  221. repository mechanism.  The flag works much like the existing
  222. `-fno-implicit-templates' flag, except that auxiliary files, with an
  223. `.rpo' extension, are built that specify what template expansions are
  224. needed.  At link time, the (patched) collect program detects missing
  225. templates and recompiles some of the object files so that the required
  226. templates are expanded.
  227.  
  228.    Note that the mechanism differs from that of cfront in that template
  229. definitions still must be visible at the point where they are to be
  230. expanded.  No assumption is made that `foo.C' contains template
  231. definitions corresponding to template declarations in `foo.h'.
  232.  
  233.    Jason Merrill writes: "To perform closure on a set of objects, just
  234. try to link them together.  It will fail, but as a side effect all
  235. needed instances will be generated in the objects."
  236.  
  237. Known bugs and problems with the repo patch
  238. *******************************************
  239.  
  240.    "The `-frepo' won't expand templated friend functions!"
  241.  
  242.    This is a known bug; currently you'll have to explicitly instantiate
  243. friend functions when using `-frepo' due to this bug (in 2.7.0 through
  244. 2.7.2 at least).
  245.  
  246.    With earlier versions of the repo patch, there was a bug that happens
  247. when you have given a quoted command line switch, something like
  248.  
  249.      -D'MESSAGE="hello there"'
  250.  
  251.    The repo code tries to recompile files using the same flags you
  252. originally specified, but doesn't quote arguments that need quoting,
  253. resulting in failures in some cases.  This is no longer a problem with
  254. the 2.7.2 patch.
  255.  
  256. The GNU Standard C++ Library
  257. ============================
  258.  
  259.    The GNU Standard C++ Library (also called the "GNU ANSI C++ Library"
  260. in places in the code) is not libg++, though it is included in the
  261. libg++ distribution.  Rather, it contains classes and functions
  262. required by the ANSI/ISO standard.  The copyright conditions are the
  263. same as those for for the iostreams classes; the LGPL is not used.  See
  264. *Note legalities::.
  265.  
  266.    This library, libstdc++, is in the libg++ distribution in versions
  267. 2.6.2 and later.  It requires at least gcc 2.6.3 to build the
  268. libg++-2.6.2 version; use at least gcc 2.7.0 to build the libg++ 2.7.0
  269. version.  It contains a hacked-up version of HP's implementation of the
  270. Standard Template Library (see *Note Standard Template Library::).  I've
  271. successfully used this Standard Template Library version to build a
  272. number of the demos you'll see on various web pages.
  273.  
  274.    As of version 2.7.0, the streams classes are now in libstdc++
  275. instead of libg++, and libiostream is being phased out (don't use it).
  276. The g++ program searches this library.
  277.  
  278. Obtaining Source Code
  279. *********************
  280.  
  281. What is the latest version of gcc, g++, and libg++?
  282. ===================================================
  283.  
  284.    The latest "2.x" version of gcc/g++ is 2.7.2, released November 26,
  285. 1995.  The latest version of libg++ is 2.7.1, released November 12,
  286. 1995.
  287.  
  288.    Don't use 2.5.x, with x less than 5, for C++ code; there were some
  289. serious bugs that didn't have easy workarounds.  2.5.8 is the most
  290. solid 2.5.x release.  2.6.3 is the most solid 2.6.x release.
  291.  
  292.    For some non-Unix platforms, the latest port of gcc may be an earlier
  293. version (2.5.8, say).  You'll need to use a version of libg++ that has
  294. the same first two digits as the compiler version, e.g. use libg++
  295. 2.5.x (for the latest x you can find) with gcc version 2.5.8.
  296.  
  297.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  298. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  299. programs, I recommend against using g++ 1.x except in special
  300. circumstances (and I can't think of any such circumstances).
  301.  
  302. How do I get a copy of g++ for Unix?
  303. ====================================
  304.  
  305.    First, you may already have it if you have gcc for your platform;
  306. g++ and gcc are combined now (as of gcc version 2.0).
  307.  
  308.    You can get g++ from a friend who has a copy, by anonymous FTP or
  309. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  310.  
  311.    The Free Software Foundation is a nonprofit organization that
  312. distributes software and manuals to raise funds for more GNU
  313. development.  Getting your copy from the FSF contributes directly to
  314. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  315. organization is buying, or $100 if an individual is buying.  Tapes cost
  316. around $200 depending on media type.  I recommend asking for version 2,
  317. not version 1, of g++.
  318.  
  319.    For more information about ordering from the FSF, contact
  320. gnu@prep.ai.mit.edu, phone (617) 542-5942 or anonymous ftp file
  321. `ftp://prep.ai.mit.edu/pub/gnu/GNUinfo/ORDERS' (you can also use one of
  322. the sites listed below if you can't get into "prep").
  323.  
  324.    Here is a list of anonymous FTP archive sites for GNU software.  If
  325. no directory is given, look in `/pub/gnu'.
  326.  
  327.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  328.      cair.kaist.ac.kr, ftp.nectec.or.th:/pub/mirrors/gnu
  329.      
  330.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  331.      
  332.      AFRICA: ftp.sun.ac.za
  333.      
  334.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  335.      
  336.      EUROPE: irisa.irisa.fr, ftp.univ-lyon1.fr, ftp.mcc.ac.uk,
  337.      unix.hensa.ac.uk:/pub/uunet/systems/gnu, ftp.denet.dk,
  338.      src.doc.ic.ac.uk:/gnu, ftp.eunet.ch, nic.switch.ch:/mirror/gnu,
  339.      ftp.informatik.rwth-aachen.de, ftp.informatik.tu-muenchen.de,
  340.      ftp.win.tue.nl, ftp.funet.fi, ftp.denet.dk, ftp.stacken.kth.se,
  341.      isy.liu.se, ftp.luth.se:/pub/unix/gnu, ftp.sunet.se, archive.eu.net
  342.      
  343.      SOUTH AMERICA: ftp.unicamp.br, ftp.inf.utfsm.cl
  344.      
  345.      WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  346.      
  347.      USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  348.      ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
  349.      jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
  350.      uiarchive.cso.uiuc.edu:/pub/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  351.      col.hp.com:/mirrors/gnu, gatekeeper.dec.com:/pub/GNU,
  352.      ftp.uu.net:/systems/gnu
  353.  
  354.    The "official site" is prep.ai.mit.edu, but your transfer will
  355. probably go faster if you use one of the above machines.
  356.  
  357.    Most GNU utilities are compressed with "gzip", the GNU compression
  358. utility.  All GNU archive sites should have a copy of this program,
  359. which you will need to uncompress the distributions.
  360.  
  361.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  362. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  363. Ohio State University.  You pay for the long-distance call to OSU; the
  364. price isn't too bad on weekends at 9600 bps.  Send mail to
  365. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  366.  
  367.    OSU lines are often busy.  If you're in the USA, and are willing to
  368. spend more money, you can get sources via UUCP from UUNET using their
  369. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  370. You will be billed $0.50/minute by your phone company.
  371.  
  372.    Don't forget to retrieve libg++ as well!
  373.  
  374. Getting gcc/g++ for the HP Precision Architecture
  375. =================================================
  376.  
  377.    If you use the HP Precision Architecture (HP-9000/7xx and
  378. HP-9000/8xx) and you want to use debugging, you'll need to use the GNU
  379. assembler, GAS (version 2.3 or later).  If you build from source, you
  380. must tell the configure program that you are using GAS or you won't get
  381. debugging support.  A non-standard debug format is used, since until
  382. recently HP considered their debug format a trade secret.  Thanks to
  383. the work of lots of good folks both inside and outside HP, the company
  384. has seen the error of its ways and has now released the required
  385. information.  The team at the University of Utah that did the gcc port
  386. now has code that understands the native HP format.
  387.  
  388.    Some enhancements for the HP that haven't been integrated back into
  389. the official GCC are available from the University of Utah, site
  390. jaguar.cs.utah.edu.  You can retrieve sources and prebuilt binaries for
  391. GCC, GDB, binutils,and libg++; see the directory `/dist'.
  392.  
  393.    The libg++ version is actually the same as the FSF 2.6.  The Utah
  394. version of GDB can now understand both the GCC and HP C compiler debug
  395. formats, so it is no longer necessary to have two different GDB
  396. versions.
  397.  
  398.    I recommend that HP users use the Utah versions of the tools (see
  399. above), though at this point the standard FSF versions will work well.
  400.  
  401.    HP GNU users can also find useful stuff on the site geod.emr.ca in
  402. the `/pub/UNIX/GNU-HP' directory.
  403.  
  404.    Jeff Law is leaving the University of Utah, so the Utah prebuilt
  405. binaries may be discontinued.
  406.  
  407. Getting gcc/g++ binaries for Solaris 2.x
  408. ========================================
  409.  
  410.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  411.  
  412.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  413. Solaris.  As a rule, these binaries are not updated as often as the
  414. sources are, so if you want the very latest version of gcc/g++, you may
  415. need to grab and install binaries for an older version and use it to
  416. bootstrap the latest version from source.
  417.  
  418.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  419. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  420. Solaris on Intel 386/486 machines (the Solaris/Intel binaries seem to
  421. be gone from prep but still exist on some mirrors).
  422.  
  423.    There are also binaries for "gzip", the GNU compression utility,
  424. which you'll need for uncompressing the binary distribution.  On any GNU
  425. archive site, look in subdirectories `i486-sun-solaris2' or
  426. `sparc-sun-solaris2'.
  427.  
  428.    The ftp directory `ftp://ftp.quintus.com/pub/GNU' contains various
  429. GNU and freeware programs for Solaris2.X running on the sparc. These are
  430. packaged to enable installation using the Solaris "pkgadd" utility.
  431. These include GNU emacs 19.27, gcc (and g++) 2.6.0, Perl 4.036, and
  432. others.
  433.  
  434. How do I get a copy of g++ for (some other platform)?
  435. =====================================================
  436.  
  437.    As of gcc-2.7.x, there is Windows NT support in gcc.  Some special
  438. utilities are required.  See the INSTALL file from the distribution.
  439. If you're interested in GNU tools on Windows NT, see
  440. `http://www.cygnus.com/misc/gnu-win32/' on the WWW, or the anonymous
  441. FTP directory `ftp://ftp.cygnus.com/pub/gnu-win32/'.
  442.  
  443.    The standard gcc/g++ distribution includes VMS support.  Since the
  444. FSF people don't use VMS, it's likely to be somewhat less solid than
  445. the Unix version.  Precompiled copies of g++ and libg++ in
  446. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  447. See also `ftp://ftp.stacken.kth.se/pub/GNU-VMS/contrib', the site (in
  448. Sweden) which has gcc-2.5.8 and libg++-2.5.3.
  449.  
  450.    There are two different versions of gcc/g++ for MS-DOS: EMX and
  451. DJGPP.  EMX also works for OS/2 and is described later.  DJGPP is DJ
  452. Delorie's port.  It can be found on many FTP archive sites; its "home"
  453. is `ftp://oak.oakland.edu/pub/msdos/djgpp/'.
  454.  
  455.    The latest version of DJGPP is 1.12.maint4, a port of gcc-2.6.3 plus
  456. support software.  This version runs under Windows 3.x.  There's also a
  457. beta-2.00 version.
  458.  
  459.    FSF sells floppies with DJGPP on them; see above for ordering
  460. software from the FSF.
  461.  
  462.    DJGPP has its own newsgroup: `news:comp.os.msdos.djgpp'.
  463.  
  464.    For information on Amiga ports of gcc/g++, retrieve the file
  465. `ftp://prep.ai.mit.edu/pub/gnu/MicrosPorts/Amiga'
  466. or write to Markus M. Wild <wild@nessie.cs.id.ethz.ch>, who I hope
  467. won't be too upset that I mentioned his name here.
  468.  
  469.    A port of gcc to the Atari ST can be found at
  470. `ftp://atari.archive.umich.edu/atari/Gnustuff/Tos' along with many
  471. other GNU programs.  This version is usually the same as the latest FSF
  472. release.  See the "Software FAQ" for the Usenet group
  473. "comp.sys.atari.st" for more information.
  474.  
  475.    There are two different ports of gcc to OS/2, the so-called EMX port
  476. (which also runs on MS-DOS), and a port called "gcc/2".  The latter
  477. port is no longer supported, since the EMX port includes all of its
  478. functionality.  The EMX port's C library attempts to provide a
  479. Unix-like environment.  For more information ask around on
  480. "comp.os.os2.programmer.misc".
  481.  
  482.    The EMX port is available by FTP from
  483.  
  484.      ftp://ftp.uni-stuttgart.de/pub/systems/os2/emx-0.9a
  485.      ftp://src.doc.ic.ac.uk/pub/packages/os2/unix/emx09a
  486.      ftp://ftp.informatik.tu-muenchen.de/pub/comp/os/os2/devtools/emx+gcc
  487.  
  488.    Eberhard Mattes did the EMX port.  His address is
  489. mattes@azu.informatik.uni-stuttgart.de.
  490.  
  491.    I'm looking for more information on gcc/g++ support on the Apple
  492. Macintosh.  Until recently, this FAQ did not provide such information,
  493. but FSF is no longer boycotting Apple as the League for Programming
  494. Freedom boycott has been dropped.
  495.  
  496.    Versions 1.37.1 and 2.3.3 of gcc were ported by Stan Shebs and are
  497. available at
  498. `ftp://ftp.cygnus.com/pub/mac'
  499.  
  500.    They are both interfaced to MPW.  Stan is working on a version using
  501. the current (post-2.7) sources, contact him directly (shebs@cygnus.com)
  502. for more information.
  503.  
  504. But I can only find g++-1.42!
  505. =============================
  506.  
  507.    "I keep hearing people talking about g++ 2.7.2 (or some other number
  508. starting with 2), but the latest version I can find is g++ 1.42.  Where
  509. is it?"
  510.  
  511.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  512. a single distribution called gcc.  If you get gcc you already have g++.
  513. The standard installation procedure for any gcc version 2 compiler will
  514. install the C++ compiler as well.
  515.  
  516.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  517. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  518.  
  519. Installation Issues and Problems
  520. ********************************
  521.  
  522. I can't build g++ 1.x.y with gcc-2.x.y!
  523. =======================================
  524.  
  525.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  526. I'm having major problems.  What's going on?"
  527.  
  528.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  529. installation instructions for g++ version 1 leave a lot to be desired,
  530. unfortunately, and I would recommend that, unless you have a special
  531. reason for needing the 1.x compiler, that C++ users use the latest
  532. g++-2.x version, as it is the version that is being actively maintained.
  533.  
  534.    There is no template support in g++-1.x, and it is generally much
  535. further away from the ANSI draft standard than g++-2.x is.
  536.  
  537. OK, I've obtained gcc; what else do I need?
  538. ===========================================
  539.  
  540.    First off, you'll want libg++ as you can do almost nothing without it
  541. (unless you replace it with some other class library).
  542.  
  543.    Second, depending on your platform, you may need "GAS", the GNU
  544. assembler, or the GNU linker (see next question).
  545.  
  546.    Finally, while it is not required, you'll almost certainly want the
  547. GNU debugger, gdb.  The latest version is 4.15.1, released November 4,
  548. 1995.  Other debuggers (like dbx, for example) will normally not be
  549. able to understand at least some of the debug information produced by
  550. g++.
  551.  
  552. Should I use the GNU linker, or should I use "collect"?
  553. =======================================================
  554.  
  555.    First off, for novices: special measures must be taken with C++ to
  556. arrange for the calling of constructors for global or static objects
  557. before the execution of your program, and for the calling of
  558. destructors at the end.  (Exception: System VR3 and System VR4 linkers,
  559. Linux/ELF, and some other systems support user-defined segments; g++ on
  560. these systems requires neither the GNU linker nor collect.  So if you
  561. have such a system, the answer is that you don't need either one).
  562.  
  563.    If you have experience with AT&T's "cfront", this function is
  564. performed there by programs named "patch" or "munch".  With GNU C++, it
  565. is performed either by the GNU linker or by a program known as
  566. "collect".  The collect program is part of the gcc-2.x distribution;
  567. you can obtain the GNU linker separately as part of the "binutils"
  568. package.  The latest version of binutils is 2.5.2, released November 2,
  569. 1994.
  570.  
  571.    (To be technical, it's "collect2"; there were originally several
  572. alternative versions of collect, and this is the one that survived).
  573.  
  574.    There are advantages and disadvantages to either choice.
  575.  
  576.    Advantages of the GNU linker:
  577.  
  578.    It's faster than using collect - collect basically runs the standard
  579. Unix linker on your program twice, inserting some extra code after the
  580. first pass to call the constructors.  This is a sizable time penalty
  581. for large programs.  The GNU linker does not require this extra pass.
  582.  
  583.    GNU ld reports undefined symbols using their true names, not the
  584. mangled names (but as of 2.7.0 so does collect).
  585.  
  586.    If there are undefined symbols, GNU ld reports which object file(s)
  587. refer to the undefined symbol(s).
  588.  
  589.    As of binutils version 2.2, on systems that use the so-called "a.out"
  590. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  591. the debug symbol table considerably.
  592.  
  593.    Advantages of collect:
  594.  
  595.    If your native linker supports shared libraries, you can use shared
  596. libraries with collect.  This used to be a strong reason *not* to use
  597. the GNU linker, but recent versions of GNU ld support linking with
  598. shared libraries on many platforms, and creating shared libraries on a
  599. few (such as Intel x86 systems that use ELF object format).
  600.  
  601.    Note: using existing shared libraries (X and libc, for example) works
  602. very nicely.  Generating shared libraries from g++-compiled code is
  603. another matter, generally requiring OS-dependent tricks if it is
  604. possible at all.  But progress has been made recently.
  605.  
  606.    As of 2.7.0, building C++ shared libraries should work fine on
  607. supported platforms (HPUX 9+, IRIX 5+, DEC UNIX (formerly OSF/1), SunOS
  608. 4, Linux/ELF and all targets using SVR4-style ELF shared libraries).
  609.  
  610.    However, as of libg++ 2.6.2, the libg++ distribution contains some
  611. patches to build libg++ as a shared library on some OSes (those listed
  612. above).  Check the file `README.SHLIB' from that distribution.
  613.  
  614.    The GNU linker has not been ported to as many platforms as g++ has,
  615. so you may be forced to use collect.
  616.  
  617.    If you use collect, you don't need to get something extra and figure
  618. out how to install it; the standard gcc installation procedure will do
  619. it for you.
  620.  
  621.    In conclusion, I don't see a clear win for either alternative at this
  622. point.  Take your pick.
  623.  
  624. Should I use the GNU assembler, or my vendor's assembler?
  625. =========================================================
  626.  
  627.    This depends on your platform and your decision about the GNU
  628. linker.  For most platforms, you'll need to use GAS if you use the GNU
  629. linker.  For some platforms, you have no choice; check the gcc
  630. installation notes to see whether you must use GAS.  But you can
  631. usually use the vendor's assembler if you don't use the GNU linker.
  632.  
  633.    The GNU assembler assembles faster than many native assemblers;
  634. however, on many platforms it cannot support the local debugging format.
  635.  
  636.    If you want to build shared libraries from gcc/g++ output and you
  637. are on a Sun, you must *not* use GNU as, as it cannot do
  638. position-independent code correctly yet.  *Note*: I've been told that
  639. this problem has been fixed in the most recent binutils release, but I
  640. haven't checked this yet.
  641.  
  642.    On HPUX or IRIX, you must use GAS (and configure gcc with the
  643. `--with-gnu-as' option) to debug your programs.  GAS is strongly
  644. recommended particularly on the HP platform because of limitations in
  645. the HP assembler.
  646.  
  647.    The GAS distribution has recently been merged with the binutils
  648. distribution, so the GNU assembler and linker are now together in this
  649. package (as of binutils version 2.5.1).
  650.  
  651. Should I use the GNU C library?
  652. ===============================
  653.  
  654.    At this point in time, no.  The GNU C library is still very young,
  655. and libg++ still conflicts with it in some places.  Use your native C
  656. library unless you know a lot about the gory details of libg++ and
  657. gnu-libc.  This will probably change in the future.
  658.  
  659. Global constructors aren't being called
  660. =======================================
  661.  
  662.    "I've installed gcc and it almost works, but constructors and
  663. destructors for global objects and objects at file scope aren't being
  664. called.  What did I do wrong?"
  665.  
  666.    It appears that you are running on a platform that requires you to
  667. install either "collect2" or the GNU linker, and you have done neither.
  668. For more information, see the section discussing the GNU linker (*Note
  669. use GNU linker?::).
  670.  
  671.    On Solaris 2.x, you shouldn't need a collect program and GNU ld
  672. doesn't run.  If your global constructors aren't being called, you may
  673. need to install a patch, available from Sun, to fix your linker.  The
  674. number of the "jumbo patch" that applies is 101409-03.  Thanks to
  675. Russell Street (r.street@auckland.ac.nz) for this info.
  676.  
  677.    It appears that on IRIX, the collect2 program is not being installed
  678. by default during the installation process, though it is required; you
  679. can install it manually by executing
  680.  
  681.      make install-collect2
  682.  
  683.    from the gcc source directory after installing the compiler.  (I'm
  684. not certain for which versions of gcc this problem occurs, and whether
  685. it is still present).
  686.  
  687. Strange assembler errors when linking C++ programs
  688. ==================================================
  689.  
  690.    "I've installed gcc and it seemed to go OK, but when I attempt to
  691. link any C++ program, I'm getting strange errors from the assembler!
  692. How can that be?"
  693.  
  694.    The messages in question might look something like
  695.  
  696.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  697.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  698.  
  699.    (on a Sun, different on other platforms).  The important thing is
  700. that the errors come out at the link step, *not* when a C++ file is
  701. being compiled.
  702.  
  703.    Here's what's going on: the collect2 program uses the Unix "nm"
  704. program to obtain a list of symbols for the global constructors and
  705. destructors, and it builds a little assembly language module that will
  706. permit them all to be called.  If you're seeing this symptom, you have
  707. an old version of GNU nm somewhere on your path.  This old version
  708. prints out symbol names in a format that the collect2 program does not
  709. expect, so bad assembly code is generated.
  710.  
  711.    The solution is either to remove the old version of GNU nm from your
  712. path (and that of everyone else who uses g++), or to install a newer
  713. version (it is part of the GNU "binutils" package).  Recent versions of
  714. GNU nm do not have this problem.
  715.  
  716. Other problems building libg++
  717. ==============================
  718.  
  719.    "I am having trouble building libg++.  Help!"
  720.  
  721.    On some platforms (for example, Ultrix), you may see errors
  722. complaining about being unable to open dummy.o.  On other platforms
  723. (for example, SunOS), you may see problems having to do with the type
  724. of size_t.  The fix for these problems is to make libg++ by saying
  725. "make CC=gcc".  According to Per Bothner, it should no longer be
  726. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  727.  
  728.    "I built and installed libg++, but g++ can't find it.  Help!"
  729.  
  730.    The string given to `configure' that identifies your system must be
  731. the same when you install libg++ as it was when you installed gcc.
  732. Also, if you used the `--prefix' option to install gcc somewhere other
  733. than `/usr/local', you must use the same value for `--prefix' when
  734. installing libg++, or else g++ will not be able to find libg++.
  735.  
  736.    The toplevel Makefile in the libg++ 2.6.2 distribution is broken,
  737. which along with a bug in g++ 2.6.3 causes problems linking programs
  738. that use the libstdc++ complex classes.  A patch for this is available
  739. from `ftp://ftp.cygnus.com//pub/g++/libg++-2.6.2-fix.gz'.
  740.  
  741. But I'm *still* having problems with `size_t'!
  742. ==============================================
  743.  
  744.    "I did all that, and I'm *still* having problems with disagreeing
  745. definitions of size_t, SIZE_TYPE, and the type of functions like
  746. `strlen'."
  747.  
  748.    The problem may be that you have an old version of `_G_config.h'
  749. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  750. platform-specific, is inserted into a different directory; most include
  751. files are in `$prefix/lib/g++-include', but this file now lives in
  752. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  753. there is an old copy of `_G_config.h' left around, remove it, otherwise
  754. g++ will find the old one first.
  755.  
  756. Do I need to rebuild libg++ to go with my new g++?
  757. ==================================================
  758.  
  759.    "After I upgraded g++ to the latest version, I'm seeing undefined
  760. symbols."
  761.  
  762.    or
  763.  
  764.    "If I upgrade to a new version of g++, do I need to reinstall
  765. libg++?"
  766.  
  767.    As a rule, the first two digits of your g++ and libg++ should be the
  768. same.  Normally when you do an upgrade in the "minor version number"
  769. (2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but there
  770. have been a couple of exceptions in the past.
  771.  
  772. Trouble installing g++ and libg++ on Linux
  773. ******************************************
  774.  
  775.    "I've downloaded the latest g++ and libg++ and I'm trying to install
  776. them on Linux, and I'm having lots of problems."
  777.  
  778.    FSF releases of libg++ won't install on Linux unchanged, since Linux
  779. uses are part of the libio library from libg++ for its standard C
  780. library, only this is changed in a way that it clashes with libg++.
  781. This means that you'll need a patched version of libg++ for it to work.
  782.  
  783.    If you want to upgrade to a new gcc/libg++ combination, the easiest
  784. thing to do is to grab the prebuilt versions of gcc and libg++ for Linux
  785. from `ftp://tsx-11.mit.edu/pub/linux/packages/GCC'.  Follow the
  786. directions carefully.  If you want to build from source, you'll need a
  787. patch for libg++; the Linux developers have named the patched libg++
  788. version libg++-2.7.1.3 and there is a patch file in the above-named
  789. directory.
  790.  
  791.    See `ftp://www.mrc-apu.cam.ac.uk/pub/linux/GCC-FAQ.html', the Linux
  792. GCC FAQ (though it may be a bit out of date; the Linux community moves
  793. quickly).
  794.  
  795. Problems with g++ on Linux Slackware 3.0
  796. ****************************************
  797.  
  798.    "When I try to compile the traditional Hello, world program on Linux,
  799. the compiler can't find `iostream.h'.  What's the deal?"
  800.  
  801.    You probably have the Slackware 3.0 release.  There's an error in the
  802. setup.  It's easy to fix, though; log in as root, and make a symbolic
  803. link:
  804.  
  805.      ln -s /usr/lib/g++-include /usr/include/g++
  806.  
  807. User Problems
  808. *************
  809.  
  810. How to silence "unused parameter" warnings
  811. ==========================================
  812.  
  813.    "When I use `-Wall' (or `-Wunused'), g++ warns about unused
  814. parameters.  But the parameters have to be there, for use in derived
  815. class functions.  How do I get g++ to stop complaining?"
  816.  
  817.    The answer is to simply omit the names of the unused parameters when
  818. defining the function.  This makes clear, both to g++ and to readers of
  819. your code, that the parameter is unused.  For example:
  820.  
  821.      int Foo::bar(int arg) { return 0; }
  822.  
  823.    will give a warning for the unused parameter `arg'.  To suppress the
  824. warning write
  825.  
  826.      int Foo::bar(int) { return 0; }
  827.  
  828. g++ objects to a declaration in a case statement
  829. ================================================
  830.  
  831.    "The compiler objects to my declaring a variable in one of the
  832. branches of a case statement.  Earlier versions used to accept this
  833. code.  Why?"
  834.  
  835.    The draft standard does not allow a goto or a jump to a case label to
  836. skip over an initialization of a variable or a class object.  For
  837. example:
  838.  
  839.      switch ( i ) {
  840.        case 1:
  841.          Object obj(0);
  842.              ...
  843.          break;
  844.        case 2:
  845.          ...
  846.          break;
  847.      }
  848.  
  849.    The reason is that `obj' is also in scope in the rest of the switch
  850. statement.
  851.  
  852.    As of version 2.7.0, the compiler will object that the jump to the
  853. second case level crosses the initialization of `obj'.  Older compiler
  854. versions would object only if class Object has a destructor.  In either
  855. case, the solution is to add a set of curly braces around the case
  856. branch:
  857.  
  858.        case 1:
  859.          {
  860.             Object obj(0);
  861.              ...
  862.             break;
  863.          }
  864.  
  865. gcc 2.5.x broke my code!  Changes in function overloading
  866. =========================================================
  867.  
  868.    "I have a program that worked just fine with older g++ versions, but
  869. as of version 2.5.x it doesn't work anymore.  Help!"
  870.  
  871.    While it's always possible that a new bug has been introduced into
  872. the compiler, it's also possible that you have been relying on bugs in
  873. older versions of g++.  For example, version 2.5.0 was the first
  874. version of g++ to correctly implement the "hiding rule."  That is, if
  875. you have an overloaded function in a base class, and in a derived class
  876. you redefine one of the names, the other names are effectively "hidden".
  877. *All* the names from the baseclass need to be redefined in the derived
  878. class.  See section 13.1 of the ARM: "A function member of a derived
  879. class is *not* in the same scope as a function member of the same name
  880. in a base class".
  881.  
  882.    Here's an example that is handled incorrectly by g++ versions before
  883. 2.5.0 and correctly by newer versions:
  884.  
  885.      class Base {
  886.      public:
  887.          void foo(int);
  888.      };
  889.      
  890.      class Derived : public Base {
  891.      public:
  892.          void foo(double);  // *note that Base::foo(int) is hidden*
  893.      };
  894.      
  895.      main() {
  896.          Derived d;
  897.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  898.      }
  899.  
  900. Where can I find a demangler?
  901. =============================
  902.  
  903.    A g++-compatible demangler named `c++filt' can be found in the
  904. `binutils' distribution.  This distribution (which also contains the
  905. GNU linker) can be found at any GNU archive site.
  906.  
  907.    As of version 2.7.0, `c++filt' is included with gcc and is installed
  908. automatically.  Even better, it is used by the `collect' linker, so you
  909. don't see mangled symbols anymore.
  910.  
  911. Where can I find a version of etags for C++?
  912. ============================================
  913.  
  914.    The libg++ distribution contains a version of etags that works for
  915. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  916. install libg++, but you can cd to that directory and type
  917.  
  918.      make etags
  919.  
  920.    after you've installed libg++.
  921.  
  922. Linker reports undefined symbols for static data members
  923. ========================================================
  924.  
  925.    "g++ reports undefined symbols for all my static data members when I
  926. link, even though the program works correctly for compiler XYZ.  What's
  927. going on?"
  928.  
  929.    The problem is almost certainly that you don't give definitions for
  930. your static data members.  If you have
  931.  
  932.      class Foo {
  933.          ...
  934.          void method();
  935.          static int bar;
  936.      };
  937.  
  938.    you have only declared that there is an int named Foo::bar and a
  939. member function named Foo::method that is defined somewhere.  You still
  940. need to define *both* method() and bar in some source file.  According
  941. to the draft ANSI standard, you must supply an initializer, such as
  942.  
  943.      int Foo::bar = 0;
  944.  
  945. in one (and only one) source file.
  946.  
  947. What does "Internal compiler error" mean?
  948. =========================================
  949.  
  950.    It means that the compiler has detected a bug in itself.
  951. Unfortunately, g++ still has many bugs, though it is a lot better than
  952. it used to be.  If you see this message, please send in a complete bug
  953. report (see next section).
  954.  
  955. I think I have found a bug in g++.
  956. ==================================
  957.  
  958.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  959. and who should I tell?"
  960.  
  961.    First, see the excellent section on bugs and bug reports in the gcc
  962. manual (which is included in the gcc distribution).  As a short summary
  963. of that section: if the compiler gets a fatal signal, for any input,
  964. it's a bug (newer versions of g++ will ask you to send in a bug report
  965. when they detect an error in themselves).  Same thing for producing
  966. invalid assembly code.
  967.  
  968.    When you report a bug, make sure to describe your platform (the type
  969. of computer, and the version of the operating system it is running) and
  970. the version of the compiler that you are running.  See the output of the
  971. command `g++ -v' if you aren't sure.  Also provide enough code so that
  972. the g++ maintainers can duplicate your bug.  Remember that the
  973. maintainers won't have your header files; one possibility is to send
  974. the output of the preprocessor (use `g++ -E' to get this).  This is
  975. what a "complete bug report" means.
  976.  
  977.    I will add some extra notes that are C++-specific, since the notes
  978. from the gcc documentation are generally C-specific.
  979.  
  980.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  981. also post to gnu.g++.bug, but it's better to use mail, particularly if
  982. you have any doubt as to whether your news software generates correct
  983. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  984.  
  985.    If your bug involves libg++ rather than the compiler, mail to
  986. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  987. guessed wrong, the maintainers will forward it to the other list.
  988.  
  989.    Second, if your program does one thing, and you think it should do
  990. something else, it is best to consult a good reference if in doubt.
  991. The standard reference is the draft working paper from the ANSI/ISO C++
  992. standardization committee, which you can get on the net.  For
  993. PostScript and PDF (Adobe Acrobat) versions, see the archive at
  994. `ftp://research.att.com/dist/stdc++/WP'.  For HTML and ASCII versions,
  995. see `ftp://ftp.cygnus.com/pub/g++'.  On the World Wide Web, see
  996. `http://www.cygnus.com/~mrs/misc/wp/'.
  997.  
  998.    An older standard reference is "The Annotated C++ Reference Manual",
  999. by Ellis and Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is
  1000. what they're talking about on the net when they refer to "the ARM".
  1001. But you should know that changes have been made to the language since
  1002. then.
  1003.  
  1004.    The ANSI/ISO C++ standards committee have adopted some changes to the
  1005. C++ language since the publication of the original ARM, and newer
  1006. versions of g++ (2.5.x and later) support some of these changes, notably
  1007. the mutable keyword (added in 2.5.0), the bool type (added in 2.6.0),
  1008. and changes in the scope of variables defined in for statements (added
  1009. in 2.7.0).  You can obtain an addendum to the ARM explaining many of
  1010. these changes by FTP from
  1011. `ftp://ftp.std.com/AW/stroustrup2e/new_iso.ps'.
  1012.  
  1013.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  1014. is NOT the standard for the language.
  1015.  
  1016. Porting programs from other compilers to g++
  1017. ============================================
  1018.  
  1019.    "I have a program that runs on <some other C++ compiler>, and I want
  1020. to get it running under g++.  Is there anything I should watch out for?"
  1021.  
  1022.    Note that g++ supports many of the newer keywords that have recently
  1023. been added to the language.  Your other C++ compiler may not support
  1024. them, so you may need to rename variables and members that conflict
  1025. with these keywords.
  1026.  
  1027.    There are two other reasons why a program that worked under one
  1028. compiler might fail under another: your program may depend on the order
  1029. of evaluation of side effects in an expression, or it may depend on the
  1030. lifetime of a temporary (you may be assuming that a temporary object
  1031. "lives" longer than the standard guarantees).  As an example of the
  1032. first:
  1033.  
  1034.      void func(int,int);
  1035.      
  1036.      int i = 3;
  1037.      func(i++,i++);
  1038.  
  1039.    Novice programmers think that the increments will be evaluated in
  1040. strict left-to-right order.  Neither C nor C++ guarantees this; the
  1041. second increment might happen first, for example.  func might get 3,4,
  1042. or it might get 4,3.
  1043.  
  1044.    The second problem often happens with classes like the libg++ String
  1045. class.  Let's say I have
  1046.  
  1047.      String func1();
  1048.      void func2(const char*);
  1049.  
  1050.    and I say
  1051.  
  1052.      func2(func1());
  1053.  
  1054.    because I know that class String has an "operator const char*".  So
  1055. what really happens is
  1056.  
  1057.      func2(func1().convert());
  1058.  
  1059.    where I'm pretending I have a convert() method that is the same as
  1060. the cast.  This is unsafe in g++ versions before 2.6.0, because the
  1061. temporary String object may be deleted after its last use (the call to
  1062. the conversion function), leaving the pointer pointing to garbage, so by
  1063. the time func2 is called, it gets an invalid argument.
  1064.  
  1065.    Both the cfront and the old g++ behaviors are legal according to the
  1066. ARM, but the powers that be have decided that compiler writers were
  1067. given too much freedom here.
  1068.  
  1069.    The ANSI C++ committee has now come to a resolution of the lifetime
  1070. of temporaries problem: they specify that temporaries should be deleted
  1071. at end-of-statement (and at a couple of other points).  This means that
  1072. g++ versions before 2.6.0 now delete temporaries too early, and cfront
  1073. deletes temporaries too late.  As of version 2.6.0, g++ does things
  1074. according to the new standard.
  1075.  
  1076.    For now, the safe way to write such code is to give the temporary a
  1077. name, which forces it to live until the end of the scope of the name.
  1078. For example:
  1079.  
  1080.      String& tmp = func1();
  1081.      func2(tmp);
  1082.  
  1083.    Finally, like all compilers (but especially C++ compilers, it seems),
  1084. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  1085. report (after checking the above issues).
  1086.  
  1087. Why does g++ mangle names differently from other C++ compilers?
  1088. ===============================================================
  1089.  
  1090.    See the answer to the next question.
  1091.  
  1092. Why can't g++ code link with code from other C++ compilers?
  1093. ===========================================================
  1094.  
  1095.    "Why can't I link g++-compiled programs against libraries compiled by
  1096. some other C++ compiler?"
  1097.  
  1098.    Some people think that, if only the FSF and Cygnus Support folks
  1099. would stop being stubborn and mangle names the same way that, say,
  1100. cfront does, then any g++-compiled program would link successfully
  1101. against any cfront-compiled library and vice versa.  Name mangling is
  1102. the least of the problems.  Compilers differ as to how objects are laid
  1103. out, how multiple inheritance is implemented, how virtual function
  1104. calls are handled, and so on, so if the name mangling were made the
  1105. same, your programs would link against libraries provided from other
  1106. compilers but then crash when run.  For this reason, the ARM
  1107. *encourages* compiler writers to make their name mangling different
  1108. from that of other compilers for the same platform.  Incompatible
  1109. libraries are then detected at link time, rather than at run time.
  1110.  
  1111. What documentation exists for g++ 2.x?
  1112. ======================================
  1113.  
  1114.    Relatively little.  While the gcc manual that comes with the
  1115. distribution has some coverage of the C++ part of the compiler, it
  1116. focuses mainly on the C compiler (though the information on the "back
  1117. end" pertains to C++ as well).  Still, there is useful information on
  1118. the command line options and the #pragma interface and #pragma
  1119. implementation directives in the manual, and there is a useful section
  1120. on template instantiation in the 2.6 version.  There is a Unix-style
  1121. manual entry, "g++.1", in the gcc-2.x distribution; the information
  1122. here is a subset of what is in the manual.
  1123.  
  1124.    You can buy a nicely printed and bound copy of this manual from the
  1125. FSF; see above for ordering information.
  1126.  
  1127.    For versions 2.6.2 and later, the gcc/g++ distribution contains the
  1128. gcc manual in PostScript.  Also, Postscript versions of GNU
  1129. documentation in U.S. letter format are available by anonymous FTP from
  1130. `ftp://primus.com/pub/gnu-ps'.  The same, in A4 format, are on
  1131. `ftp://liasun3.epfl.ch/pub/gnu/ps-doc'.
  1132.  
  1133.    A draft of a document describing the g++ internals appears in the gcc
  1134. distribution (called g++int.texi); it is incomplete but gives lots of
  1135. information.
  1136.  
  1137. Problems with the template implementation
  1138. =========================================
  1139.  
  1140.    g++ does not implement a separate pass to instantiate template
  1141. functions and classes at this point; for this reason, it will not work,
  1142. for the most part, to declare your template functions in one file and
  1143. define them in another.  The compiler will need to see the entire
  1144. definition of the function, and will generate a static copy of the
  1145. function in each file in which it is used.
  1146.  
  1147.    (The experimental template repository code (see *Note repository::)
  1148. that can be added to 2.7.0 or later does implement a separate pass, but
  1149. there is still no searching of files that the compiler never saw).
  1150.  
  1151.    For version 2.6.0, however, a new switch `-fno-implicit-templates'
  1152. was added; with this switch, templates are expanded only under user
  1153. control.  I recommend that all g++ users that use templates read the
  1154. section "Template Instantiation" in the gcc manual (version 2.6.x and
  1155. newer).  g++ now supports explicit template expansion using the syntax
  1156. from the latest C++ working paper:
  1157.  
  1158.      template class A<int>;
  1159.      template ostream& operator << (ostream&, const A<int>&);
  1160.  
  1161.    As of version 2.6.3, there are still a few limitations in the
  1162. template implementation besides the above (thanks to Jason Merrill for
  1163. this info):
  1164.  
  1165.   1. Static data member templates are not supported.  You can work
  1166.      around this by explicitly declaring the static variable for each
  1167.      template specialization:
  1168.  
  1169.           template <class T> struct A {
  1170.             static T t;
  1171.           };
  1172.           
  1173.           template <class T> T A<T>::t = 0; // gets bogus error
  1174.           int A<int>::t = 0;                // OK (workaround)
  1175.  
  1176.      (still a limitation in 2.7.0)
  1177.  
  1178.   2. Template member names are not available when defining member
  1179.      function templates.
  1180.  
  1181.           template <class T> struct A {
  1182.             typedef T foo;
  1183.             void f (foo);
  1184.             void g (foo arg) { ... }; // this works
  1185.           };
  1186.           
  1187.           template <class T> void A<T>::f (foo) { } // gets bogus error
  1188.  
  1189.   3. Templates are instantiated using the parser.  This results in two
  1190.      problems:
  1191.  
  1192.      a) Class templates are instantiated in some situations where such
  1193.      instantiation should not occur.
  1194.  
  1195.           template <class T> class A { };
  1196.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  1197.  
  1198.      b) Function templates cannot be inlined at the site of their
  1199.      instantiation.
  1200.  
  1201.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  1202.           
  1203.           void f () {
  1204.             int i = min (1, 0);           // not inlined
  1205.           }
  1206.           
  1207.           void g () {
  1208.             int j = min (1, 0);           // inlined
  1209.           }
  1210.  
  1211.      A workaround that works in version 2.6.1 and later is to specify
  1212.  
  1213.           extern template int min (int, int);
  1214.  
  1215.      before `f()'; this will force it to be instantiated (though not
  1216.      emitted).
  1217.  
  1218.   4. Member function templates are always instantiated when their
  1219.      containing class is.  This is wrong.
  1220.  
  1221. I get undefined symbols when using templates
  1222. ============================================
  1223.  
  1224.    (Thanks to Jason Merrill for this section).
  1225.  
  1226.    g++ does not automatically instantiate templates defined in other
  1227. files.  Because of this, code written for cfront will often produce
  1228. undefined symbol errors when compiled with g++.  You need to tell g++
  1229. which template instances you want, by explicitly instantiating them in
  1230. the file where they are defined.  For instance, given the files
  1231.  
  1232.    `templates.h':
  1233.      template <class T>
  1234.      class A {
  1235.      public:
  1236.        void f ();
  1237.        T t;
  1238.      };
  1239.      
  1240.      template <class T> void g (T a);
  1241.  
  1242.    `templates.cc':
  1243.      #include "templates.h"
  1244.      
  1245.      template <class T>
  1246.      void A<T>::f () { }
  1247.      
  1248.      template <class T>
  1249.      void g (T a) { }
  1250.  
  1251.    main.cc:
  1252.      #include "templates.h"
  1253.      
  1254.      main ()
  1255.      {
  1256.        A<int> a;
  1257.        a.f ();
  1258.        g (a);
  1259.      }
  1260.  
  1261.    compiling everything with `g++ main.cc templates.cc' will result in
  1262. undefined symbol errors for `A<int>::f ()' and `g (A<int>)'.  To fix
  1263. these errors, add the lines
  1264.  
  1265.      template class A<int>;
  1266.      template void g (A<int>);
  1267.  
  1268.    to the bottom of `templates.cc' and recompile.
  1269.  
  1270. I get multiply defined symbols using templates
  1271. ==============================================
  1272.  
  1273.    You may be running into a bug that was introduced in version 2.6.1
  1274. (and is still present in 2.6.3) that generated external linkage for
  1275. templates even when neither `-fexternal-templates' nor
  1276. `-fno-implicit-templates' is specified.  There is a patch for this
  1277. problem at
  1278. `ftp://ftp.cygnus.com/pub/g++/gcc-2.6.3-template-fix'.
  1279.  
  1280.    I recommend either applying the patch or using
  1281. `-fno-implicit-templates' together with explicit template instantiation
  1282. as described in previous sections.
  1283.  
  1284.    This bug is fixed in 2.7.0.
  1285.  
  1286. Does g++ support the Standard Template Library?
  1287. ===============================================
  1288.  
  1289.    From Per Bothner:
  1290.  
  1291.    The Standard Template Library (STL) uses many of the extensions that
  1292. the ANSI/ISO committee has made to templates, and g++ doesn't support
  1293. some of these yet.  So if you grab HP's free implementation of STL it
  1294. isn't going to work.  However, libg++-2.6.2 contains a hacked version
  1295. of STL, based on work by Carsten Bormann, which permits gcc-2.6.3 to
  1296. compile at least the containers.  A full implementation is going to
  1297. need improved template support, which will take a while yet.
  1298.  
  1299.    As of libg++-2.7.0 and gcc-2.7.0, I've succeeded in making many short
  1300. STL example programs work, though there are still a number of bugs and
  1301. limitations.  Almost all of the ObjectSpace examples (a set of over 200
  1302. simple examples of STL usage) now work.
  1303.  
  1304.    There are several commercial suppliers of STL implementations;
  1305. ObjectSpace's version supports gcc-2.7.x.
  1306.  
  1307.    Mumit Khan has produced an "STL newbie guide" with lots of
  1308. information on using STL with gcc.  See
  1309.  
  1310.    `http://www.xraylith.wisc.edu/~khan/software/stl/STL.newbie.html'
  1311.  
  1312. What are the differences between g++ and the ARM specification of C++?
  1313. ======================================================================
  1314.  
  1315.    As of version 2.7.0, g++ has exception support on most but not all
  1316. platforms (no support on MIPS-based platforms yet), but it doesn't work
  1317. right if optimizaton is enabled, which means the exception
  1318. implementation is still not really ready for production use.
  1319.  
  1320.    Some features that the ANSI/ISO standardization committee has voted
  1321. in that don't appear in the ARM are supported, notably the `mutable'
  1322. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  1323. type `bool', with constants `true' and `false'.  The beginnings of
  1324. run-time type identification are present, so there are more reserved
  1325. words: `typeid', `static_cast', `reinterpret_cast', `const_cast', and
  1326. `dynamic_cast'.
  1327.  
  1328.    As with any beta-test compiler, there are bugs.  You can help improve
  1329. the compiler by submitting detailed bug reports.
  1330.  
  1331.    One of the weakest areas of g++ other than templates is the
  1332. resolution of overloaded functions and operators in complex cases.  The
  1333. usual symptom is that in a case where the ARM says that it is ambiguous
  1334. which function should be chosen, g++ chooses one (often the first one
  1335. declared).  This is usually not a problem when porting C++ code from
  1336. other compilers to g++, but shows up as errors when code developed under
  1337. g++ is ported to other compilers.  (I believe this is no longer a
  1338. significant problem in 2.7.0).
  1339.  
  1340.    [A full bug list would be very long indeed, so I won't put one here.
  1341. I may add a list of frequently-reported bugs and "non-bugs" like the
  1342. static class members issue mentioned above].
  1343.  
  1344. Will g++ compile InterViews?  The NIH class library?  Rogue Wave?
  1345. =================================================================
  1346.  
  1347.    The NIH class library uses a non-portable, compiler-dependent hack
  1348. to initialize itself, which makes life difficult for g++ users.  It
  1349. will not work without modification, and I don't know what modifications
  1350. are required or whether anyone has done them successfully.
  1351.  
  1352.    In short, it's not going to happen any time soon (previous FAQs
  1353. referred to patches that a new NIHCL release would hopefully contain,
  1354. but this hasn't happened).
  1355.  
  1356.    *Note:* I thought I saw an item indicating that someone *had*
  1357. patched NIHCL to work with g++.  Any pointers?
  1358.  
  1359.    I think that as of version 2.5.6, the standard g++ will compile the
  1360. standard 3.1 InterViews completely successfully.  Note that you'll need
  1361. the `-fno-for-scope' flag if you use gcc-2.7.0; with 2.7.2 you may be
  1362. able to omit this flag but you'll get warnings.
  1363.  
  1364.    According to Jason Merrill, the latest g++ (2.7.0) works with Rogue
  1365. Wave's `tools.h++' class library, but you may want to grab
  1366. `ftp://ftp.cygnus.com/pub/g++/Tools.h++-6.1-patch'.  Again, you'll need
  1367. the `-fno-for-scope' flag since Rogue Wave hasn't fixed their code to
  1368. comply with the new standard yet.
  1369.  
  1370. Debugging on SVR4 systems
  1371. =========================
  1372.  
  1373.    "How do I get debugging to work on my System V Release 4 system?"
  1374.  
  1375.    Most systems based on System V Release 4 (except Solaris) encode
  1376. symbolic debugging information in a format known as `DWARF'.
  1377.  
  1378.    Although the GNU C compiler already knows how to write out symbolic
  1379. debugging information in the DWARF format, the GNU C++ compiler does
  1380. not yet have this feature, nor is it likely to in the immediate future.
  1381.  
  1382.    Ron Guilmette has done a great deal of work to try to get the GNU
  1383. C++ compiler to produce DWARF format symbolic debugging information
  1384. (for C++ code) but he gave up on the project because of a lack of
  1385. funding and/or interest from the g++ user community.  If you have a
  1386. strong desire to see this project completed, contact Ron at
  1387. <rfg@netcom.com>.
  1388.  
  1389.    In the meantime, you *can* get g++ debugging under SVR4 systems by
  1390. configuring gcc with the `--with-stabs' option.  This causes gcc to use
  1391. an alternate debugging format, one more like that used under SunOS4.
  1392. You won't need to do anything special to GDB; it will always understand
  1393. the "stabs" format.
  1394.  
  1395. X11 conflicts with libg++ in definition of String
  1396. =================================================
  1397.  
  1398.    "X11 and Motif define String, and this conflicts with the String
  1399. class in libg++.  How can I use both together?"
  1400.  
  1401.    One possible method is the following:
  1402.  
  1403.      #define String XString
  1404.      #include <X11/Intrinsic.h>
  1405.      /* include other X11 and Motif headers */
  1406.      #undef String
  1407.  
  1408.    and remember to use the correct `String' or `XString' when you
  1409. declare things later.
  1410.  
  1411. Why can't I assign one stream to another?
  1412. =========================================
  1413.  
  1414.    [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  1415.  
  1416.    Assigning one stream to another seems like a reasonable thing to do,
  1417. but it's a bad idea.  Usually, this comes up because people want to
  1418. assign to `cout'.  This is poor style, especially for libraries, and is
  1419. contrary to good object-oriented design.  (Libraries that write directly
  1420. to `cout' are less flexible, modular, and object-oriented).
  1421.  
  1422.    The iostream classes do not allow assigning to arbitrary streams,
  1423. because this can violate typing:
  1424.  
  1425.      ifstream foo ("foo");
  1426.      istrstream str(...);
  1427.      foo = str;
  1428.      foo->close ();  /* Oops! Not defined for istrstream! */
  1429.  
  1430.    The original cfront implementation of iostreams by Jerry Schwarz
  1431. allows you to assign to `cin', `cout', `cerr', and `clog', but this is
  1432. not part of the draft standard for iostreams and generally isn't
  1433. considered a good idea, so standard-conforming code shouldn't use this
  1434. technique.
  1435.  
  1436.    The GNU implementation of iostream did not support assigning to
  1437. `cin', `cout', `cerr', and `clog' for quite a while, but it now does,
  1438. for backward compatibility with cfront iostream (versions 2.6.1 and
  1439. later of libg++).
  1440.  
  1441.    The ANSI/ISO C++ Working Paper does provide ways of changing the
  1442. streambuf associated with a stream.  Assignment isn't allowed; there is
  1443. an explicit named member that must be used.
  1444.  
  1445.    However, it is not wise to do this, and the results are confusing.
  1446. For example: `fstream::rdbuf' is supposed to return the *original*
  1447. filebuf, not the one you assigned. (This is not yet implemented in GNU
  1448. iostream.)  This must be so because `fstream::rdbuf' is defined to
  1449. return a `filebuf *'.
  1450.  
  1451. What are the rules for shipping code built with g++ and libg++?
  1452. ***************************************************************
  1453.  
  1454.    "Is it is possible to distribute programs for profit that are created
  1455. with g++ and use the g++ libraries?"
  1456.  
  1457.    I am not a lawyer, and this is not legal advice.  In any case, I have
  1458. little interest in telling people how to violate the spirit of the GNU
  1459. licenses without violating the letter.  This section tells you how to
  1460. comply with the intention of the GNU licenses as best I understand them.
  1461.  
  1462.    The FSF has no objection to your making money.  Its only interest is
  1463. that source code to their programs, and libraries, and to modified
  1464. versions of their programs and libraries, is always available.
  1465.  
  1466.    The short answer is that you do not need to release the source to
  1467. your program, but you can't just ship a stripped executable either,
  1468. unless you use only the subset of libg++ that includes the iostreams
  1469. classes (see discussion below) or the new libstdc++ library (available
  1470. in libg++ 2.6.2 and later).
  1471.  
  1472.    Compiling your code with a GNU compiler does not affect its
  1473. copyright; it is still yours.  However, in order to ship code that
  1474. links in a GNU library such as libg++ there are certain rules you must
  1475. follow.  The rules are described in the file COPYING.LIB that
  1476. accompanies gcc distributions; it is also included in the libg++
  1477. distribution.  See that file for the exact rules.  The agreement is
  1478. called the Library GNU Public License or LGPL.  It is much "looser"
  1479. than the GNU Public License, or GPL, that covers must GNU programs.
  1480.  
  1481.    Here's the deal: let's say that you use some version of libg++,
  1482. completely unchanged, in your software, and you want to ship only a
  1483. binary form of your code.  You can do this, but there are several
  1484. special requirements.  If you want to use libg++ but ship only object
  1485. code for your code, you have to ship source for libg++ (or ensure
  1486. somehow that your customer already has the source for the exact version
  1487. you are using), and ship your application in linkable form.  You cannot
  1488. forbid your customer from reverse-engineering or extending your program
  1489. by exploiting its linkable form.
  1490.  
  1491.    Furthermore, if you modify libg++ itself, you must provide source
  1492. for your modifications (making a derived class does not count as
  1493. modifying the library - that is "a work that uses the library").
  1494.  
  1495.    For certain portions of libg++ that implement required parts of the
  1496. C++ language (such as iostreams and other standard classes), the FSF has
  1497. loosened the copyright requirement still more by adding the "special
  1498. exception" clause, which reads as follows:
  1499.  
  1500.      As a special exception, if you link this library with files
  1501.      compiled with GCC to produce an executable, this does not cause
  1502.      the resulting executable to be covered by the GNU General Public
  1503.      License.  This exception does not however invalidate any other
  1504.      reasons why the executable file might be covered by the GNU
  1505.      General Public License.
  1506.  
  1507.    If your only use of libg++ uses code with this exception, you may
  1508. ship stripped executables or license your executables under different
  1509. conditions without fear of violating an FSF copyright.  It is the intent
  1510. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1511. draft standard are developed, these will also be placed under this
  1512. "special exception" license.  The code in the new libstdc++ library,
  1513. intended to implement standard classes as defined by ANSI/ISO, is also
  1514. licensed this way.
  1515.  
  1516.    To avoid coming under the influence of the LGPL, you can link with
  1517. `-liostream' rather than `-lg++' (for version 2.6.x and earlier), or
  1518. `-lstdc++' now that it is available.  In version 2.7.0 all the standard
  1519. classes are in `-lstdc++'; you can do the link step with `c++' instead
  1520. of `g++' to search only the `-lstdc++' library and avoid the LGPL'ed
  1521. code in `-lg++'.
  1522.  
  1523. -- 
  1524. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  1525.  
  1526. Work for something because it is good,
  1527. not just because it stands a chance to succeed.       -- Vaclav Havel
  1528.